package com.example.orderflow.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.example.orderflow.entity.enums.PageSize;
import com.example.orderflow.entity.query.RoleInfoQuery;
import com.example.orderflow.entity.po.RoleInfo;
import com.example.orderflow.entity.vo.PaginationResultVO;
import com.example.orderflow.entity.query.SimplePage;
import com.example.orderflow.mappers.RoleInfoMapper;
import com.example.orderflow.service.RoleInfoService;
import com.example.orderflow.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("roleInfoService")
public class RoleInfoServiceImpl implements RoleInfoService {

	@Resource
	private RoleInfoMapper<RoleInfo, RoleInfoQuery> roleInfoMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<RoleInfo> findListByParam(RoleInfoQuery param) {
		return this.roleInfoMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(RoleInfoQuery param) {
		return this.roleInfoMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<RoleInfo> findListByPage(RoleInfoQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<RoleInfo> list = this.findListByParam(param);
		PaginationResultVO<RoleInfo> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(RoleInfo bean) {
		return this.roleInfoMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<RoleInfo> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.roleInfoMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<RoleInfo> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.roleInfoMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(RoleInfo bean, RoleInfoQuery param) {
		StringTools.checkParam(param);
		return this.roleInfoMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(RoleInfoQuery param) {
		StringTools.checkParam(param);
		return this.roleInfoMapper.deleteByParam(param);
	}

	/**
	 * 根据RoleName获取对象
	 */
	@Override
	public RoleInfo getRoleInfoByRoleName(String roleName) {
		return this.roleInfoMapper.selectByRoleName(roleName);
	}

	/**
	 * 根据RoleName修改
	 */
	@Override
	public Integer updateRoleInfoByRoleName(RoleInfo bean, String roleName) {
		return this.roleInfoMapper.updateByRoleName(bean, roleName);
	}

	/**
	 * 根据RoleName删除
	 */
	@Override
	public Integer deleteRoleInfoByRoleName(String roleName) {
		return this.roleInfoMapper.deleteByRoleName(roleName);
	}
}